public class test05 {
    /*
// Definition for a Node.
class Node {
    public int val;
    public List<Node> children;

    public Node() {}

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, List<Node> _children) {
        val = _val;
        children = _children;
    }
};
*/
        public List<List<Integer>> levelOrder(Node root) {
            List<List<Integer>> res = new ArrayList<>();
            Queue<Node> queue = new LinkedList<>();
            if(root==null){
                return res;
            }
            queue.offer(root);
            while(!queue.isEmpty()){
                int len = queue.size();
                List<Integer> list = new ArrayList<>();
                for(int i = 0;i<len;i++){
                    Node tmpNode = queue.poll();
                    list.add(tmpNode.val);
                    if(tmpNode.children!=null){
                        List<Node> children = tmpNode.children;
                        for(Node child:children){
                            queue.offer(child);
                        }
                    }
                }
                res.add(list);
            }
            return res;
        }
}
